package pm.devices;

import pm.config.Configuration;
import pm.devices.drives.DrivesUtil;
import pm.devices.drives.DrivesChecker;
import pm.devices.drives.DrivesListener;
import pm.devices.drives.Drive;

import java.math.BigDecimal;
import java.io.File;

public class DevicesModuleImpl implements DevicesModule, DrivesListener {

    private DevicesModuleListener hardwareModuleListener;
    private Configuration configuration;

    public DevicesModuleImpl(DevicesModuleListener hardwareModuleListener, Configuration configuration) {
        this.hardwareModuleListener = hardwareModuleListener;
        this.configuration = configuration;
        init();
    }

    private void init() {
        System.loadLibrary(this.configuration.getNativeLibName());
        DrivesChecker drivesChecker = new DrivesChecker(this.configuration.getDrivesUpdateTime());
        drivesChecker.addListener(this);
        new Thread(drivesChecker).start();
    }

    public Drive[] getDrives() {
        return DrivesUtil.getDrives(null);
    }

    public void ejectChange(BigDecimal change) {
        //todo
    }

    public File scanToFile() {
        //todo
        return null;
    }

    public void drivesChanged(Drive[] updatedDrives) {
        hardwareModuleListener.drivesChanged(updatedDrives);
    }
}
